<?php
class utilities{
    /*
    * This breaks a date time string stored in the database into an array of dd mm yyyy hh mm ss
    * 
    * $datetime (string) - Datetime string from the database exactly as it was stored
    * 
    * Return (array) - A break down of the MySQL datetime stuff in an array (see next line for structure)
    *   Year => $year, Month => $month, Day => $day, Hour => $hour, Minute => $minute, Second => $second
    */
    public function breakDateTime($datetime){
        //Validates $datetime
            //This is something I got from another site, I don't understand regualr expressions well enough at the moment to 
            //be sure this is correct but so far it seems to have worked.
            //Feel free to let me know if it isn't!
        if(!preg_match('^([1-3][0-9]{3,3})-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][1-9]|3[0-1])\s([0-1][0-9]|2[0-4]):([0-5][0-9]):([0-5][0-9])$^', $datetime))
            die("Incorrect date time value: Class - general | Method - breakDateTime");

        $year = substr($datetime, 0, 4);
        $month = substr($datetime, 5, 2);
        $day = substr($datetime, 8, 2);

        $hour = substr($datetime, 11, 2);
        $minute = substr($datetime, 14, 2);
        $second = substr($datetime, 17, 2);

        $datetime_array = array("year" => $year, "month" => $month, "day" => $day, "hour" => $hour, "minute" => $minute, "second" => $second);

        return $datetime_array;
    }
}
?>